package BiShi.tengxun;

import java.util.LinkedList;
import java.util.Scanner;

public class Main4 {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        LinkedList<Integer> q = new LinkedList<>();
        while(sc.hasNext()){
            q.clear();
            int M = sc.nextInt();
            sc.nextLine();
            while ( M-- > 0){
                String cop = sc.nextLine();
                helper(cop,q);

            }
        }
    }

    private static void helper(String cop, LinkedList<Integer> q) {
        if(cop.contains("add")){
            q.add(Integer.valueOf(cop.split(" ")[1]));
        }
        else if(cop.equals("poll")){
            if(q.size()==0){
                System.out.println(-1);
            }else{
                //  System.out.println(q.getFirst());
                q.removeFirst();
            }
        }
        else{
            if(q.size()==0){
                System.out.println(-1);
            }
            else System.out.println(q.getFirst());
        }
    }
}



